package 富婆梦.第一阶段.第三周.练习题;

import java.util.ArrayList;

public class DotCom {
    //保存位置的ArrayList
    private ArrayList<String> locationCells;
    //DotCom的名称
    private String name;

    public void setLocationCells(ArrayList<String> loc) {
        locationCells = loc;
    }

    public void setName(String n) {
        name = n;
    }

    public String checkYourself(String userInput) {
        String result = "miss";
        //返回list中内容是userInput的索引位置，如果没找到，会返回-1
        int index = locationCells.indexOf(userInput);
        if (index >= 0) {
            locationCells.remove(index);
            result = "hit";
            System.out.println("You hit " + name);
            if (locationCells.isEmpty()) {
                result = "sunk";
                System.out.println("You sunk " + name);
            }
        }
        return result;
    }
}
